package com.kyrie.kafka;

import org.apache.kafka.clients.producer.RecordMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.support.ProducerListener;

/***
 * 描述: kafka生产者发送回调监听器
 *
 * @author wuxiang
 * @date 2020-04-23 16:27
 */
public class KafkaProducerListener implements ProducerListener {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * kafka消息发送成功回调方法
     */
    @Override
    public void onSuccess(String topic, Integer partition, Object key, Object value, RecordMetadata recordMetadata) {
        logger.info("kafka send ok: [topic:{},partition:{},key:{},value:{},recordMetadata:{}]",topic,partition,key,value,recordMetadata);
    }

    /**
     * kafka消息发送失败回调方法
     */
    @Override
    public void onError(String topic, Integer partition, Object key, Object value, Exception exception) {
        logger.info("kafka send error: [topic:{},partition:{},key:{},value:{},exception:{}]",topic,partition,key,value,exception);
    }
}
